package com.example.demo.service.lxy;

import com.example.demo.dao.lxy.RoleUserDao;
import com.example.demo.entity.Role_User;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleUserServiceImpl implements RoleUserService {
    @Autowired(required=true)
    RoleUserDao roleUserDao;

    @Override
    public List<Role_User> findAll() {
        List<Role_User> roleUserList= roleUserDao.findAll();
        return roleUserList;
    }

    @Override
    public List<Role_User> findByid(int userid) {
        List<Role_User> roleUserList= roleUserDao.findByid(userid);
        return roleUserList;
    }

    @Override
    public List<Role_User> insertUser(int userid, int roleid) {
        int useridtemp=userid;
        int adduser=roleUserDao.insertUser(useridtemp, roleid);
        if (adduser==1){
            List<Role_User> roleUserList= roleUserDao.findByid(useridtemp);
            return roleUserList;
        }else {
            return null;
        }
    }
    @Override
    public List<Role_User> delectUser(int userid) {
        int id=userid;
         int deleteSingle = roleUserDao.delectUser(id);
        if(deleteSingle>=1){
            List<Role_User> roleUserList= roleUserDao.findAll();
            return roleUserList;
        } else {
            System.out.println("无数据");
            return null;
        }
    }

    @Override
    public List<Role_User> upadeUser(int userid, int roleid) {
        int useridtmp = userid;
        int updateUser = roleUserDao.upadeUser(useridtmp,roleid);
        if (updateUser>=1){
            List<Role_User> roleUserList= roleUserDao.findByid(useridtmp);
            return roleUserList;
        } else {
            return null;
        }
    }
}